package jobs;


import input.XmlInputFormat;
import mappers.ImportXMLFileMapper;
import reducers.ImportXMLFileReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.log4j.Logger;


public class ImportInputFile extends Configured implements Tool {
	
	private static final Logger sLogger = Logger.getLogger(ImportInputFile.class);

	@Override
	public int run(String[] arg0) throws Exception {
	//public static void run() throws Exception {
		
		//SAXBuilder builder = new SAXBuilder();
		
		Configuration conf = getConf();
		//conf.set("stream.recordreader.class", "org.apache.hadoop.streaming.StreamXmlRecordReader");
		conf.set("xmlinput.start", "<contact>");
		conf.set("xmlinput.end", "</contact>");
		
		Job job = new Job(conf, "ImportXMLFile");
		
		
		job.setJarByClass(ImportInputFile.class);
		job.setMapperClass(ImportXMLFileMapper.class);
		job.setReducerClass(ImportXMLFileReducer.class);
		
		
		job.setInputFormatClass(XmlInputFormat.class);	
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(Text.class);

		FileInputFormat.addInputPath(job, new Path("input"));
		FileOutputFormat.setOutputPath(job, new Path("output"));			
		
		job.waitForCompletion(true);
		
		return 0;
	}
	
	public static void main(String[] args) throws Exception {

		int res = ToolRunner.run(new Configuration(), new ImportInputFile(), args);
		//run();
		System.exit(res);
	  }

}
